//
//  ViewController.m
//  City
//
//  Created by Justsoso on 16/3/3.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic,strong) NSArray *arr1;
@property (nonatomic,strong) NSArray *arr2;
@property (nonatomic,strong) NSDictionary *dict1;
@property (nonatomic,strong) NSDictionary *dict2;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSString *path = [[NSBundle mainBundle] pathForResource:@"area1" ofType:@"plist"];
    self.arr1 = [NSArray arrayWithContentsOfFile:path];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.arr1.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *arr = self.arr1[section][@"Cities"];
    NSMutableArray *mArr = [NSMutableArray array];
    for (NSDictionary *tmp in arr)
    {
        [mArr addObject:tmp[@"city"]];
    }
    return mArr.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    
    NSArray *arr = self.arr1[indexPath.section][@"Cities"];
    NSMutableArray *mArr = [NSMutableArray array];
    for (NSDictionary *tmp in arr)
    {
        [mArr addObject:tmp[@"city"]];
    }
    cell.textLabel.text = mArr[indexPath.row];
    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return self.arr1[section][@"State"];
}

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    NSMutableArray *mArr = [NSMutableArray array];
    for (NSDictionary *tmp in self.arr1)
    {
        [mArr addObject:tmp[@"State"]];
    }
    return mArr;
}

@end
